import 'package:flutter_axrjc/datasource/network/api/LightApi.dart';
import 'package:flutter_axrjc/datasource/network/request/exp.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

import 'state.dart';

class ReportMonthLogic extends GetxController {
  final ReportMonthState state = ReportMonthState();
  var page = 1;

  var refreshController = RefreshController(initialRefresh: true);
  Future<void> getList({required bool isRefresh}) async {
    if (isRefresh) {
      state.list.clear();
      page = 1;
    } else {
      page++;
    }
    try {
      state.list.addAll(await LightApi.getMonthReportList(page: page));
    } on ApiException catch (e) {
      EasyLoading.showToast(e.message);
    } catch (e) {
      print(e);
    }
    if (isRefresh) {
      refreshController.refreshCompleted();
    } else {
      refreshController.loadComplete();
    }
  }
}
